<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="日期">
              <a-date-picker @change="onChangeBegin" />-
              <a-date-picker @change="onChangeEnd" />

            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="供应商">
              <a-input placeholder="供应商" v-model="queryParam.key"></a-input>
            </a-form-item>
          </a-col>

          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否付(退)款">
                <a-select v-model="queryParam.state">
                  <a-select-option value="1">是</a-select-option>
                  <a-select-option value="2">否</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->


    <!-- table区域-begin -->
    <div>

      <!--
      :pagination="ipagination"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      rowKey="id"
      -->
      <a-table
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: getNumberToPay}"
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="number"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        class="j-table-force-nowrap"
        :pagination=false
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
      </a-table>
    </div>

    <br/>

    <div v-show="clickState">
      <!--
      ref="cTable"
      -->
      <a-table
        rowKey="id"
        size="middle"
        :scroll="{x:true}"
        bordered
        :columns="cColumns"
        :dataSource="cData"
        :loading="loading"
        class="j-table-force-nowrap"
        :pagination=false>

      </a-table>
    </div>

    <jxc-purchase-list-modal ref="modalForm" @ok="modalFormOk"></jxc-purchase-list-modal>
  </a-card>
  <!--<a-card :bordered="false" v-show="clickState">

  </a-card>-->
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JxcPurchaseListModal from './modules/JxcPurchaseListModal'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  // import JDate from '@/components/jeecg/JDate.vue'
  import { putAction,postAction,getAction } from '@/api/manage'

  export default {
    name: 'JxcPurchaseListList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDictSelectTag,
      JxcPurchaseListModal
    },
    data () {
      return {
        description: 'jxc_purchase_list管理页面',
        // 表头
        columns: [
          {
            title: '',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'供应商',
            align:"center",
            dataIndex: 'supplierName'
          },
          {
            title:'日期',
            align:"center",
            dataIndex: 'date'
          },
          {
            title:'单号',
            align:"center",
            dataIndex: 'number'
          },
          {
            title:'类型',
            align:"center",
            dataIndex: 'type'
          },
          {
            title:'实付金额',
            align:"center",
            dataIndex: 'paid'
          },
          {
            title:'应付金额',
            align:"center",
            dataIndex: 'payable'
          },

          {
            title:'付(退)款状态',
            align:"center",
            dataIndex: 'state'
          },

          {
            title:'操作员',
            align:"center",
            dataIndex: 'trueName'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remarks'
          },
        ],
        url: {
          list: "/purchaseListGoods/list",
        },
        dictOptions:{},

        selectedNumber:undefined,  // 获取选中行
        clickState:false,          // 单号数据是否。。

        cColumns:[
          {
            title:'商品编码',
            align:"center",
            dataIndex: 'goodsCode'
          },
          {
            title:'商品名称',
            align:"center",
            dataIndex: 'goodsName'
          },
          {
            title:'商品型号',
            align:"center",
            dataIndex: 'goodsModel'
          },
          {
            title:'单价',
            align:"center",
            dataIndex: 'price',
            customRender:function (t,r) {
              return "￥"+r.total;
            }
          },
          {
            title:'数量',
            align:"center",
            dataIndex: 'goodsNum'
          },
          {
            title:'单位',
            align:"center",
            dataIndex: 'goodsUnit'
          },

          {
            title:'总金额',
            align:"center",
            dataIndex: 'total',
            customRender:function (t,r) {
              return "￥"+r.total;
            }
          },
        ],
        cData:[
          // {
          //   id:"126",
          //   goodsCode:"0009",
          //   goodsName:"休闲",
          //   goodsModel:"240g",
          //   price:"20",
          //   goodsNum:"4",
          //   goodsUnit:"袋",
          //   total:"80",
          // }
        ],

      }
    },
    created() {

    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      // 获取时间范围
      onChangeBegin(date,dateString){
        this.queryParam.begin = dateString;
      },
      onChangeEnd(date,dateString){
        this.queryParam.end = dateString;
      },
      getNumberToPay(selectedRowKeys) {
        if (this.selectedNumber != selectedRowKeys[0]){
          this.selectedNumber = selectedRowKeys[0];
        }else {
          this.cData=[];
          this.selectedNumber=undefined;
          this.clickState=false;
          return ;
        }
        console.log(this.selectedNumber);

        getAction("purchaseListGoods/"+this.selectedNumber).then((resp)=>{
          if(resp.success){
            console.log(resp.result);
            this.cData = resp.result;
            this.clickState=true;
          }
        })
      },

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>